package com.risk.modules.rm.service.impl;

import com.risk.modules.rm.entity.Dictionary;
import com.risk.modules.rm.entity.Rule;
import com.risk.modules.rm.dao.DictionaryDao;
import com.risk.modules.rm.dao.RuleDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

@Service
public class RuleServiceImpl {

    @Autowired
    private RuleDao ruleDao;
    @Autowired
    private DictionaryDao dictionaryDao;

    public void add(Rule rule){
        rule.setId(UUID.randomUUID().toString().replace("-",""));
        ruleDao.add(rule);
    }

    static int pageSize = 10;
    public List<Rule> pageByCondition(int page,Rule rule){
        String whereClause = "";

        List<Rule> ruleList = ruleDao.pageByCondition((page - 1) * pageSize,pageSize,whereClause);

        return ruleList;
    }

    public int countByCondition(Rule rule){
        return ruleDao.countByCondition("");
    }

    public void del(String id){
        ruleDao.del(id);
    }

    public List<Dictionary> getTypeList(){
        return dictionaryDao.queryByCondition(" and parent_id = " + 1);
    }
}
